using System;
using System.Collections.Generic;
using System.Text;
using AopLoadBalancer.Server.DataAccess;

namespace AopLoadBalancer.Server.BusinessLogic
{
    public class AliveHostTracker
    {
        private string serviceId;
        private string serviceUrl;

        public AliveHostTracker(string serviceId, string serviceUrl)
        {
            this.serviceId = serviceId;
            this.serviceUrl = serviceUrl;
        }

        public List<String> GetAliveHosts()
        {
            using(DalSession session=new DalSession(ServerConfig.ConnectionString))
            {
                DateTime aliveLastTick = DateTime.Now - AliveNotifier.notificationInterval;
                AliveNotificationDal dal=new AliveNotificationDal(session);

                List<AliveNotification> aliveNotifications=dal.GetByLastAliveTick(serviceId, aliveLastTick);

                List<string> urls=aliveNotifications.ConvertAll<string>(delegate(AliveNotification a) { return a.ServiceUrl; });
                return urls;
            }   

        }
    }
}
